package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.component.util.CommonUtil;
import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.ResultEnum;
import com.qumitech.visualnovel.pubdef.dto.chat.*;
import com.qumitech.visualnovel.service.chat.ChatMsgService;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @author ywxie
 * @date 2019/8/19 10:03
 * @description
 */
@RestController
@RequestMapping("/api/chatmsg")
public class ChatMsgController {

    @Autowired
    private ChatMsgService chatMsgService;

    @GetMapping("")
    public BaseRsp getChatMsg(ChatMsgAdminQueryDTO chatMsgAdminQueryDTO){
        return chatMsgService.getChatMsgList(chatMsgAdminQueryDTO);
    }


    @PutMapping("/change_status")
    public BaseRsp consoleUpdateChatMsg(@RequestBody ChatMsgAdminUpdateDTO updateDTO)
    {
        return chatMsgService.updateChatMsg(updateDTO);

    }

    @GetMapping("/risk_word")
    public BaseRsp listRiskWord(RiskWordQueryDTO queryDTO)
    {
        chatMsgService.listRiskWord(queryDTO);
        return new BaseRsp(ResultEnum.SUCCESS, ImmutableMap.of("words", chatMsgService.listRiskWord(queryDTO),
                "count", chatMsgService.countRiskWord(queryDTO)));
    }


    @PostMapping("/risk_word")
    public BaseRsp addRiskWord(@RequestBody RiskWordSaveDTO saveDTO)
    {
        chatMsgService.addRiskWord(saveDTO);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @PutMapping("/risk_word/{id}")
    public BaseRsp updateRiskWord(@PathVariable("id") Long id,
                                  @RequestBody RiskWordUpdateDTO updateDTO)
    {
        updateDTO.setId(id);
        chatMsgService.updateRiskWord(updateDTO);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @DeleteMapping("/risk_word/{id}")
    public BaseRsp rmRiskWord(@PathVariable("id") Long id)
    {
        chatMsgService.rmRiskWord(id);
        return new BaseRsp(ResultEnum.SUCCESS);
    }
}
